from django.db import models
from users.models import BaseModel,User

# Create your models here.

class ChatData(BaseModel):
    chat_a = models.ForeignKey(User,  related_name='chat_1', on_delete=models.CASCADE, verbose_name='用户A')
    chat_bir = models.ForeignKey(User,  related_name='chat_b', on_delete=models.CASCADE, verbose_name='用户B')
    friendname = models.CharField(max_length=100, null=True, blank=True, verbose_name='备注')
    types = models.IntegerField(default=0,verbose_name='聊天内容类型')
    chat_data = models.CharField(max_length=500, verbose_name='聊天信息')
    status = models.BooleanField(default=0, verbose_name='是否已读读')

    class Meta:
        db_table = 'tb_chat'
        verbose_name = '聊天信息'
        verbose_name_plural = verbose_name

class GroupData(BaseModel):
    '''群表'''
    master = models.ForeignKey(User, related_name='master', on_delete=models.CASCADE, verbose_name='群主' )
    groupname = models.CharField(max_length=20, verbose_name='群名称')
    notice = models.CharField(max_length=500, default='暂无信息', verbose_name='群公告')
    group_img = models.CharField(max_length=150, default='http://120.24.182.152:5555/s/static/s/image_files/users_image/userss.png',verbose_name='群头像')
    new_data = models.CharField(null=True,blank=True ,max_length=500, verbose_name='最新消息')

    class Meta:
        db_table = 'tb_group'
        verbose_name = '群'
        verbose_name_plural = verbose_name


class GroupUser(BaseModel):
    '''群信设置表'''
    user = models.ForeignKey(User, on_delete=models.CASCADE, related_name='user_g', verbose_name='用户')
    group = models.ForeignKey(GroupData, on_delete=models.CASCADE, related_name='group_g', verbose_name='群')
    inner_name = models.CharField(max_length=30, null=True, blank=True, verbose_name='群内名')
    tip = models.IntegerField(default=0, verbose_name='未读消息数')
    status = models.BooleanField(default=0, verbose_name='是否屏蔽')

    class Meta:
        db_table = 'tb_group_user'
        verbose_name = '群设置'
        verbose_name_plural = verbose_name


class GroupMessage(BaseModel):
    '''群信息表'''
    user = models.ForeignKey(User, on_delete=models.CASCADE, related_name='user_gg', verbose_name='用户')
    group = models.ForeignKey(GroupData, on_delete=models.CASCADE, related_name='group_gg', verbose_name='群')
    types = models.IntegerField(default=0, verbose_name='聊天内容类型')
    chat_data = models.CharField(null=True, blank=True, max_length=500, verbose_name='聊天信息')
    status = models.BooleanField(default=0, verbose_name='是否已读')

    class Meta:
        db_table = 'tb_group_message'
        verbose_name = '群消息'
        verbose_name_plural = verbose_name